Skip to content

feat(cdr): export push and queue pipeline metrics - #269

Open
ftong2010 wants to merge 1 commit into
restsend:mainfrom
ftong2010:cdr-queue-metrics
Open

feat(cdr): export push and queue pipeline metrics#269
ftong2010 wants to merge 1 commit into
restsend:mainfrom
ftong2010:cdr-queue-metrics

Conversation

@ftong2010

Copy link
Copy Markdown

Motivation

The CDR pipeline — call producers → bounded queue ([callrecord] channel_capacity) → manager → saver (http / database / local /
s3) — has no observability. When the configured endpoint slows down,
records pile up in the bounded channel and are dropped with only a warn
log (call record channel full; dropping record); nothing surfaces in
/metrics, so CDR loss stays invisible until reconciliation. This adds
the same pipeline observability the RWI webhook path got in #267.

What this PR adds

  1. Pipeline metrics covering enqueue → queue → saver push (table below).
  2. Drop accounting at the bounded-channel boundary: try_send
    failures (Full and Closed) now count cdr_records_dropped_total
    in addition to the existing warn.
  3. Queue depth gauges sampled every 5 s, plus the configured
    capacity as a static gauge.
  4. Opt-in queueing-latency histogram via [callrecord] track_queue_latency — measures queue wait only (record enqueued →
    manager dequeued). A slow saver endpoint inflates backlog, not this
    histogram.

Metrics

Metric Type Labels Description
cdr_records_enqueued_total Counter - CDRs accepted into the queue
cdr_records_pushed_total Counter - CDRs persisted by the saver (batch success)
cdr_records_push_failed_total Counter - CDRs in batches the saver failed to persist
cdr_records_dropped_total Counter - CDRs lost (queue full or manager gone)
cdr_queue_size Gauge - Configured queue capacity
cdr_queue_current Gauge - CDRs currently queued (sampled every 5 s)
cdr_queue_latency_seconds Histogram - Queueing wait; opt-in via track_queue_latency

Healthy pipeline: enqueued == pushed, dropped == 0, queue_current
near 0.

Implementation notes

  • The enqueue instant rides in CallRecord.extensions (RecordEnqueuedAt,
    never serialized) so the channel item type is unchanged; only the
    histogram recording is config-gated.
  • pushed / push_failed are counted per saver batch, matching the
    CallRecordSaver contract (batch-level Ok/Err).

Configuration

Key Default Description
[callrecord] track_queue_latency false Record the queueing-wait histogram

Verification

10 cps × 60 s load test (600 calls, type = "http" saver to an external
router), with track_queue_latency = true:

  • cdr_records_enqueued_total 600 == cdr_records_pushed_total 600;
    dropped 0, push_failed 0
  • cdr_queue_size 2048; cdr_queue_current 0 after drain
  • Histogram: 600 samples, p50 ≤ 5 ms, p95 ≤ 0.5 s, avg ≈ 59 ms

cargo test --lib callrecord: 75 pass; the 3 failing recording/sipflow
upload tests fail identically on unmodified main (pre-existing,
unrelated). Note: cargo test --lib currently needs #268 to compile.

Docs

docs/observability.md gains a "Call Record (CDR) Pipeline" metrics
section; docs/config/06-media-recording.md documents the pipeline
options and links to it.

Mirror the RWI webhook pipeline observability for CDR: producers now
count enqueues and drops at the bounded-channel boundary (reporter
try_send), the manager counts pushed vs push-failed records per saver
batch, and queue depth/capacity gauges are sampled every 5s. An opt-in
[callrecord] track_queue_latency flag records the queueing-wait
histogram cdr_queue_latency_seconds (enqueued → manager dequeued) via
a transient RecordEnqueuedAt instant stashed in the record extensions —
save/push time is excluded by design.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant